package com.org.Bibliotech;

import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.*;

public class LibraryTest {

    private  Book HeadFirstJava = new Book("Head First Java", "Kathy Sierra & Bert Bates", 2003);
    private Book AnnaKarenina = new Book("Anna Karenina", "Leo Tolstoy", 1877);
   private ArrayList<Book> books = new ArrayList<Book>();




   @Test
   public void testGetAvailableBooks(){


       books.add(HeadFirstJava);
       books.add(AnnaKarenina);

       Library library = new Library(books);


        assertEquals(books, library.getAvailableBooks());

    }

    @Test
    public void testCheckoutBook(){
        books.add(HeadFirstJava);
        books.add(AnnaKarenina);

        Library library = new Library(books);

        assertTrue(library.getAvailableBooks().contains(HeadFirstJava));
        assertFalse(library.getCheckedOutBooks().contains(HeadFirstJava));

        assertTrue(library.checkoutBook(HeadFirstJava));

        assertFalse(library.getAvailableBooks().contains(HeadFirstJava));
        assertTrue(library.getCheckedOutBooks().contains(HeadFirstJava));

    }


    @Test
    public void testReturnBook(){
        books.add(HeadFirstJava);
        books.add(AnnaKarenina);

        Library library = new Library(books);

        assertTrue(library.checkoutBook(HeadFirstJava));
        assertFalse(library.getAvailableBooks().contains(HeadFirstJava));
        assertTrue(library.getCheckedOutBooks().contains(HeadFirstJava));

        //assertTrue(library.getCheckedOutBooks().contains(new Book("Head First Java", "Kathy Sierra & Bert Bates", 2003)));
        assertTrue(library.returnBook(new Book("Head First Java", "Kathy Sierra & Bert Bates", 2003)));
        //assertTrue(library.returnBook(HeadFirstJava));

        assertTrue(library.getAvailableBooks().contains(HeadFirstJava));
        assertFalse(library.getCheckedOutBooks().contains(HeadFirstJava));

    }

}